package com.license.presentation.employee;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.license.common.util.Constants;
import com.license.logic.behaviorlog.FileHelper;
import com.license.logic.behaviorlog.WriteXML;
import com.license.logic.dao.EmployeeDAO;
import com.license.logic.pojo.SmallEmployee;
import com.license.logic.profile.EmployeeProfile;

public class EmployeePresentation {
	
	private EmployeeDAO employeeDAO;
	
	public EmployeePresentation(){
		employeeDAO = new EmployeeDAO();
	}
	
	public void createEmployee(EmployeeProfile employeeProfile) throws Exception{
		WriteXML configFile = new WriteXML();
		configFile.setExternDirectoryPath(Constants.EXTERN_FILE_PATH_UNCLASSIFIED);
	    configFile.saveEmployee(Constants.EXTERN_FILE_PATH_UNCLASSIFIED + "\\" + employeeProfile.getPersonalProfile().getName() + ".xml", employeeProfile);
	}
	
	public List<SmallEmployee> getSmallEmployees(String directoryPath, int pageNumber){
		return employeeDAO.getEmployeesNames(directoryPath, pageNumber);
	}
	
	public List<SmallEmployee> getAllSmallEmployees(String directoryPath){
		return employeeDAO.getAllEmployeesNames(directoryPath);
	}
	
	public void deleteEmployee(String fileName){
		FileHelper fileHelper = new FileHelper();
		fileHelper.deleteFile(fileName);
	}
	
	public EmployeeProfile selectEmployee(String filePath) throws ParserConfigurationException, SAXException, IOException{
		FileHelper fileHelper = new FileHelper();
		return fileHelper.getEmployeeProfile(filePath);
	}
	
	public int countAllEmployee(String directoryPath){
		return employeeDAO.countAllEmployee(directoryPath);
	}

}
